package com.overseasShopping.Action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.overseasShopping.Biz.ComplaintBiz;
import com.overseasShopping.pojo.Complaint;
import com.overseasShopping.pojo.User;

public class ComplaintAction {
	private ComplaintBiz complaintBiz;
	private int comscript;
	private String title;
	private String contact;
	private String content;
	public ComplaintBiz getComplaintBiz() {
		return complaintBiz;
	}
	public void setComplaintBiz(ComplaintBiz complaintBiz) {
		this.complaintBiz = complaintBiz;
	}
	public int getComscript() {
		return comscript;
	}
	public void setComscript(int comscript) {
		this.comscript = comscript;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContact() {
		return contact;
	}
	public void setContact(String contact) {
		this.contact = contact;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String precomplaint(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		User user=(User)session.get("user");
		String userId=user.getUserId();
		List<Complaint> complaintlist=complaintBiz.getmycomplaintlistByuserid(userId);
		if(complaintlist!=null&&complaintlist.size()>0){
			for (Complaint complaint : complaintlist) {
				Complaint com=complaint;
			}
		}
		
		session.put("complaintlist", complaintlist);
		return "tocomplaint";
	}
	@SuppressWarnings("unchecked")
	public String todetailInfo(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		Complaint complaint= ((List<Complaint>)session.get("complaintlist")).get(comscript-1);
		List<Complaint> complaintlist=(List<Complaint>) session.get("complaintlist");
		session.put("comsize", complaintlist.size());
		session.put("comscript", comscript);
		session.put("currcomplaint", complaint);
		return "todetailInfo";
		
	}
	public String add(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		User user=(User)session.get("user");
		user.getUserId();
		Complaint complaint =new Complaint(title, new Date(), "投诉", "undo", contact, content, user, null); 
		complaintBiz.save(complaint);
		return "addsuccess";
	}
	public String del(){
		Map<String, Object> session=ActionContext.getContext().getSession();
		Complaint complaint =(Complaint) session.get("currcomplaint");
		complaint.setCstate("del");
		complaintBiz.update(complaint);
		return "addsuccess";
	}
	
}
